//===============================================================================
// Microsoft patterns & practices Enterprise Library Contribution
// Policy Injection Application Block
//===============================================================================

using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;
using Microsoft.Practices.EnterpriseLibrary.PolicyInjection.Configuration;
using Microsoft.Practices.Unity;
using Microsoft.Practices.Unity.InterceptionExtension;
using EntLibContrib.PolicyInjection.MatchingRules;

namespace EntLibContrib.PolicyInjection.Configuration
{
	/// <summary>
	/// And Matching Rule Data
	/// </summary>
	public class AndMatchingRuleData : CompositeMatchingRuleData
	{
		#region Construction
		/// <summary>
		/// Initializes a new instance of the <see cref="AndMatchingRuleData"/> class.
		/// </summary>
		public AndMatchingRuleData()
		{
		}

		/// <summary>
		/// Initializes a new instance of the <see cref="AndMatchingRuleData"/> class.
		/// </summary>
		/// <param name="matchingRuleName">Name of the matching rule.</param>
		public AndMatchingRuleData(string matchingRuleName)
			: base(matchingRuleName, typeof(AndMatchingRule))
		{
		}
		#endregion

		#region Public Methods
		/// <summary>
		/// Adds the rule represented by this configuration object to <paramref name="policy"/>.
		/// </summary>
		/// <param name="policy">The policy to which the rule must be added.</param>
		/// <param name="configurationSource">The configuration source from which additional information
		/// can be retrieved, if necessary.</param>
		public override void ConfigurePolicy(PolicyDefinition policy, IConfigurationSource configurationSource)
		{
			policy.AddMatchingRule<AndMatchingRule>(
					new InjectionConstructor(
						new InjectionParameter<NameTypeConfigurationElementCollection<MatchingRuleData, CustomMatchingRuleData>>(this.MatchingRules)));
		}
		#endregion
	}
}
